<template>
  <!--用户列表-->
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix fs28">
        选择用户推送
      </div>
      <user-list @getTemplateRow="getTemplateRow" ref="userList"></user-list>
      <div class="bottom clearfix">
        <el-button @click="back()">取 消</el-button>
        <el-button type="primary"  @click="sendMessage">确认添加</el-button>
      </div>
    </el-card>
  </div>
</template>

<script>
  import userList from '@/components/userList'
  import {
    sendNotify
  } from '@/api/course'
  export default {
    components: {
      userList
    },

    data() {
      return {
        userVisible: false,
        formExtension: {},
        dayId: null
      }
    },

    mounted() {
      this.dayId = this.$route.params.id;
      console.log(this.$route)

    },
    methods: {
      sendMessage() {
        console.log(this.$refs.userList.multipleSelection)
        if(this.$refs.userList.multipleSelection.length == 0){
            return this.$message.error("请选择人员");
        }
        sendNotify({
          dayId: this.dayId,
          usrId: [...this.$refs.userList.multipleSelection.map(item => item.uid)]
        }).then(res => {
          res ? this.$message.success('添加成功') : this.$message.error('添加失败')
        })
      },
      modalPicTap(dayId) {
        this.userVisible = true
      },
      back() {
        this.$router.go(-1);
      },
      //多选用户定时推送
      getTemplateRow(row) {
        this.formExtension.image = row.avatar
        this.formExtension.spreadUid = row.uid
      },

    }
  }
</script>

<style >
  .el-dialog__wrapper {
    top: -100px
  }
  .fs28 {
    font-size: 20px;
  }
  .bottom{
    text-align: right;
  }
</style>
